package com.ming.demo.easyiot;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.LinearLayout;

/**
 * Created by Administrator on 2018/1/30.
 */

public class GestureDemoView extends LinearLayout {
    //1,定义GestureDetector类
    private GestureDetector m_gestureDetector;
    GestureDetector.OnGestureListener onGestureListener;
    Boolean isTouch = false;

    public GestureDemoView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GestureDemoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setClickable(false);
        //设置为可点击
//        setClickable(true);
        //2,初始化手势类，同时设置手势监听
        //双击监听-一般很少用到
    }

    public void closeListen() {
    }

    public void setMyListener(Context context, GestureDetector.OnGestureListener onGestureListener) {
        setClickable(true);
        isTouch = true;
        this.onGestureListener = onGestureListener;
        m_gestureDetector = new GestureDetector(context, onGestureListener);

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        //3,将touch事件交给gesture处理
        if (isTouch)
            m_gestureDetector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }


}